package com.example.security2.service;

import com.example.security2.mapper.UserMapper;
import com.example.security2.pojo.MyUser;
import com.example.security2.pojo.MyUserDetails;
import com.example.security2.pojo.Result;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MyUser myUser = userMapper.getUserByUsername(username);
        if (myUser == null){
            throw  new RuntimeException("用户名不存在");
        }

        MyUserDetails myUserDetails = new MyUserDetails(myUser);

        return myUserDetails;
    }
}
